#include<stdio.h>
#include<unistd.h>
#include<pthread.h>


pthread_mutex_t mutex1;
pthread_mutex_t mutex2;

void* pthread_mutexA(void*arg){
    pthread_mutex_lock(&mutex1);
    sleep(1);
    pthread_mutex_lock(&mutex2);
    pthread_mutex_unlock(&mutex2);
    pthread_mutex_unlock(&mutex1);
}

void* pthread_mutexB(void*arg){
    pthread_mutex_lock(&mutex2);
    sleep(1);
    pthread_mutex_lock(&mutex1);
    pthread_mutex_unlock(&mutex1);
    pthread_mutex_unlock(&mutex2);
}
int main(){

    pthread_mutex_init(&mutex1,NULL);
    pthread_mutex_init(&mutex2,NULL);
    pthread_t tid;
    int ret = pthread_create(&tid,NULL,pthread_mutexA,NULL);
    if(ret<0){
        perror("pthread_create");
        return 0;
    }
    ret = pthread_create(&tid,NULL,pthread_mutexB,NULL);
    if(ret<0){
        perror("pthread_create");
        return 0;
    }
    while(1){
        sleep(1);
    }
    pthread_mutex_destroy(&mutex1);

    pthread_mutex_destroy(&mutex2);
    return 0;
}
